package com.doge.config;

import com.doge.util.converter.DateConverter;
import com.doge.util.interceptor.LogInterceptor;
import org.hibernate.validator.HibernateValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: doge
 * @description:
 * @author: Keyu Li
 * @create: 2021-11-30 14:07
 **/

@Configuration
public class MvcConfiguration implements WebMvcConfigurer {
    private static final String UPLOADED_FOLDER = System.getProperty("user.dir")+"/src/main/resources/static/pic/";

    /*
    * 静态资源映射：展示图片
    * */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/wx/storage/fetch/**")
                .addResourceLocations("file:"+UPLOADED_FOLDER );
    }

    @Autowired
    LogInterceptor interceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor)
                .addPathPatterns("/admin/admin/**")
                .addPathPatterns("/admin/order/**")
                .addPathPatterns("/admin/auth/**");
    }

    /*
    * converter输入映射配置
    * */
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new DateConverter());
    }
}
